package com.hygj.util;

/**
 * @author hygl
 */
public class FileUtils {

    /**
     * 获取当前类数据
     *
     * @return
     */
    public static String getWebClassesPath() {
        return FileUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
    }

    public static String getWebInfPath() {
        String path = getWebClassesPath();
        if (path.indexOf("WEB-INF") > 0) {
            path = path.substring(0, path.indexOf("WEB-INF") + 8);
        }
        return path;
    }

    public static String getWebRoot() {
        String path = getWebClassesPath();
        if (path.indexOf("WEB-INF") > 0) {
            path = path.substring(0, path.indexOf("WEB-INF/classes"));
        }
        if (path.contains("/ROOT")) {
            return path.replace("/ROOT", "");
        }
        return path;
    }

}
